package 力扣._78_子集;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

class Solution {
    void trackBack(int[] nums, int now_i, List<Integer> t_list, List<List<Integer>> result) {
        if (now_i == nums.length) {
            List<Integer> t = new ArrayList<>(t_list.size());
            t.addAll(t_list);
            result.add(t);
            return;
        }
        // 不添加
        trackBack(nums, now_i + 1, t_list, result);
        // 添加
        t_list.add(nums[now_i]);
        trackBack(nums, now_i + 1, t_list, result);
        // 恢复现场
        t_list.remove(t_list.size() - 1);
    }

    public List<List<Integer>> subsets(int[] nums) {
        List<Integer> t_list = new LinkedList<>();
        List<List<Integer>> result = new LinkedList<>();
        trackBack(nums, 0, t_list, result);
        return result;
    }
}